# author: SA12226114(Xin Zhu) SA12226139(Dan Shu)

# set compile arguments
CC = gcc
CFLAGS = -g

# avoid warning info about "up to date"
.PHONY: target

# generate object file and execute file
target: dbclient.o dbserver.o dbapi.o socketwrapper.o util.o debug.o threadpool.o router.o dbmemcache.o
	$(CC) $(CFLAGS) dbclient.o dbapi.o socketwrapper.o util.o debug.o -ltokyocabinet -o dbclient
	$(CC) $(CFLAGS) dbserver.o dbapi.o socketwrapper.o util.o debug.o threadpool.o -lpthread -ltokyocabinet -o dbserver
	$(CC) $(CFLAGS) socketwrapper.o util.o debug.o threadpool.o router.o -lpthread -L. -L./router -L./router/bin -lconhash -o dbrouter
	$(CC) $(CFLAGS) socketwrapper.o util.o debug.o threadpool.o dbmemcache.o -lpthread -o dbmemcache
	@echo "====================================================================="
	@echo "=                        compile successfully                       ="
	@echo "====================================================================="


dbclient.o:
	$(CC) $(CFLAGS) -c ./client/dbclient.c -O -o $@

dbserver.o:
	$(CC) $(CFLAGS) -c ./server/dbserver.c -o $@

dbapi.o:
	$(CC) $(CFLAGS) -c ./server/dbapi.c -o $@

socketwrapper.o: 
	$(CC) $(CFLAGS) -c ./communicate/socketwrapper.c -o $@

util.o:
	$(CC) $(CFLAGS) -c ./common/util.c -o $@

debug.o:
	$(CC) $(CFLAGS) -c ./common/debug.c -o $@

threadpool.o:
	$(CC) $(CFLAGS) -c ./threadpool/threadpool.c -o $@

router.o:
	$(CC) $(CFLAGS) -c ./router/router.c -o $@

dbmemcache.o:
	$(CC) $(CFLAGS) -c ./memcache/dbmemcache.c -o $@

# clean rubbish
clean:
	rm -f *.o *.hdb *~ dbclient dbserver dbrouter dbmemcache
	@echo "====================================================================="
	@echo "=                        clean successfully                         ="
	@echo "====================================================================="

